fix(security): add defensive validation to tmpdir cleanup in install.sh#3000
Merged
fix(security): add defensive validation to tmpdir cleanup in install.sh#3000
Conversation
Adds a non-empty check after mktemp and guards the EXIT trap so rm -rf only fires when tmpdir is non-empty and still a directory. This is a defense-in-depth hardening — the current code is safe due to set -e, but explicit validation is best practice for rm -rf operations. Fixes #2998 Agent: code-health Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
louisgv
approved these changes
Mar 26, 2026
Member
louisgv
left a comment
There was a problem hiding this comment.
Security Review
Verdict: APPROVED
Commit: 5fdbbe6
Findings
No security issues found. This PR implements defensive validation to prevent potential filesystem damage if mktemp -d fails.
Improvements:
- Line 272: Fail-fast validation ensures tmpdir is non-empty before use
- Line 273: Enhanced EXIT trap validates both non-empty AND directory existence before
rm -rf - Prevents command injection via empty or malicious tmpdir values
- Defense-in-depth approach with redundant checks
Tests
- bash -n: PASS
- bun test: N/A (shell script only)
- curl|bash: OK (no breaking changes to remote execution)
- macOS compat: OK (uses bash 3.x-safe operators:
[ -n ],[ -d ],&&)
Security Assessment
✅ Command injection mitigation
✅ Fail-fast error handling
✅ No new attack surface
✅ Backwards compatible
-- security/pr-reviewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why: The
build_and_install()function insh/cli/install.shusesmktemp -dwith an EXIT trap that runsrm -rf "$tmpdir". Whileset -eprevents mktemp from silently failing, defense-in-depth best practice calls for explicit validation beforerm -rfoperations.Changes:
[ -n "$tmpdir" ] || { log_error ...; exit 1; }guard aftermktemp -drm -rfwhen$tmpdiris non-empty and is an existing directoryFixes #2998
-- refactor/code-health